import {createRouter, createWebHistory} from 'vue-router'

import pinia from '../stores/index';
import { useUserInfoStore } from '../stores/userInfo';
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '',
      redirect:'/homepage'
    },
    {
      path: '/work',
      name: 'work',
      component: () => import('@/views/Publics.vue')
    },
    {
      path: '/publics',
      name: 'publics',
      component: () => import('@/views/Publics.vue')
    },
    {
      path: '/publish',
      name: 'publish',
      component: () => import('@/views/Publish.vue')
    },
    {
      path: '/homepage',
      name: 'homepage',
      component: () => import('@/views/HomePage.vue')
    },
    {
      path: '/PersonalSpace',
      name: 'PersonalSpace',
      component: () => import('@/views/PersonalSpace.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/Register.vue')
    },
    {
      path: '/person',
      name: 'person',
      component: () => import('@/views/Person.vue')
    },
    {
      path: '/notice',
      name: 'notice',
      component: () => import('@/views/Notice.vue')
    },
    {
      path: '/shownotice',
      name: 'shownotice',
      component: () => import('@/views/ShowNotice.vue')
    },
    {
      path: '/user',
      name: 'user',
      component: () => import('@/views/User.vue')
    },
    {
      path: '/searchResult',
      name: 'searchResult',
      component: () => import('@/views/SearchResult.vue')
    }
  ]
});

const userInfoStore = useUserInfoStore(pinia)

//全局前置守卫
// router.beforeEach(async (to, from, next) => {
//   const token = getToken()
//   if (token||to.path=="/register") {

//     next()
//   }else{
//     if(to.path!="/login"){
//       next({path:"login"})
//     }else{
//       next()
//     }
//   }

// });

export default router
